<!DOCTYPE html>
<html>
<head>
    <title>修改医生--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });
        });
    </script>
</head>
<body>
<form id="editForm" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td><input type="hidden" id="id" name="id" value="">
                <input type="text" name="doctorName" id="doctorName" value=""/></td>
        </tr>

        <tr>
            <td width="10%" class="tableleft">身份证号</td>
            <td><input type="text" name="idNumber" id="idNumber" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">手机</td>
            <td><input type="text" name="phone" id="phone" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">座机</td>
            <td><input type="text" name="telPhone" id="telPhone" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">性别</td>
            <td><input type="radio" name="sex" id="nan" value="1" checked/>男&nbsp;&nbsp;&nbsp;
                <input type="radio"
                       name="sex" id="nv"
                       value="0"/>女
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">出生年月</td>
            <td><input type="date" name="bday" id="bday" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">年龄</td>
            <td>
                <div id="age"></div>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">电子邮箱</td>
            <td><input type="text" name="email" id="email" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">所属科室</td>
            <td><select id="department" name="department"></select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">学历</td>
            <td><select id="eduction" name="eduction">
                <option value="专科">专科</option>
                <option value="本科">本科</option>
                <option value="博士">博士</option>
                <option value="博士后">博士后</option>
            </select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><textarea id="description" name="description"></textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <input class="btn btn-primary" type="button" value="保存" onclick="update()">
                    <button
                            type="button" class="btn btn-success" name="backid" id="backid">返回列表
                    </button>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
<script>
    function oneValues() {
        var result;
        var url = window.location.search; //获取url中"?"符后的字串
        if (url.indexOf("?") != -1) {
            result = url.substr(url.indexOf("=") + 1);
        }
        return result;
    }

    loadFunction()

    function loadFunction() {
        $.ajax({
            type: "GET",
            url: "/Doctor/findDoctorById",
            data: {"id": oneValues()},
            dataType: "json",
            success: function (vo) {
                console.log(vo);
                let data = vo.obj;
                $("#id").val(oneValues());
                $("#doctorName").val(data.doctorName);
                $('#idNumber').val(data.idNumber);
                $('#phone').val(data.phone);
                $('#telPhone').val(data.telPhone);
                data.sex == 1 ? $("#nan").prop('checked', true) : $("#nv").prop('checked', true);
                document.getElementById('age').innerHTML = data.age + "岁";

                var birthday = new Date(data.birthday);
                var year = birthday.getFullYear();
                var month = birthday.getMonth();
                if(month<10){
                    month = "0"+month;
                }
                var date = birthday.getDate();
                if(date<10){
                    date = "0"+date;
                }
                let showbirthday  = year+'-'+month+'-'+date;
                $('#bday').attr("value",showbirthday)
                findDept(data.department);
                $('#email').val(data.email);
                $('#eduction').val(data.eduction);
                $('#description').val(data.description);


            }
        });
    }

    function findDept(result) {
        $.ajax({
            type: "GET",
            url: "/dept/findDept",
            dataType: "json",
            success: function (vo) {
                let data = vo.list;

                let str = "";
                for (let i = 0; i < data.length; i++) {
                    if (result == data[i].deptId) {
                        str += "<option selected='selected'  value=\" " + data[i].deptId + "\" >" + data[i].deptName + "</option>\n"
                    } else {
                        str += "<option  value=\" " + data[i].deptId + "\" >" + data[i].deptName + "</option>\n"
                    }

                }
                $("#department").html(str);

            },
        })

    }
    function update(){
        $.ajax({
            type: "POST",
            url: "/Doctor/updateForDoctor",
            data: $('#editForm').serialize(),
            dataType: "json",
            success: function (vo) {
                alert("修改成功")
                window.location.href="index.html";
            },
            error:function (vo){
                alert("添加失败")
            }
        })
    }
</script>
</html>